﻿<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/6
 * Time: 14:38
 */

header("Content-Type:text/html;charset=utf-8");

function getNumberByName()
{

    include_once('./Classes/PHPExcel.php');

    error_reporting(E_ALL);
    ini_set('display_errors', TRUE);
    ini_set('display_startup_errors', TRUE);
//date_default_timezone_set('Europe/London');
    $data = [];

    $PHPExcel = new PHPExcel();
    $filename = '2018.xlsx';
//如果excel文件后缀名为.xls，导入这个类
    $exts = substr($filename, (strrpos($filename, ".") + 1));
    if ($exts == 'xls') {
        include_once('./Classes/PHPExcel/Reader/Excel5.php');
        $PHPReader = new \PHPExcel_Reader_Excel5();
    } else if ($exts == 'xlsx') {
        include_once('./Classes/PHPExcel/Reader/Excel2007.php');
        $PHPReader = new \PHPExcel_Reader_Excel2007();
    }
//载入文件
    $PHPExcel = $PHPReader->load($filename);
//获取表中的第一个工作表，如果要获取第二个，把0改为1，依次类推

    $currentSheet = $PHPExcel->getSheet(0);
//获取总列数
    $allColumn = $currentSheet->getHighestColumn();
//获取总行数
    $allRow = $currentSheet->getHighestRow();
//循环获取表中的数据，$currentRow表示当前行，从哪行开始读取数据，索引值从0开始
    for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {
        //从哪列开始，A表示第一列
        for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
            //数据坐标
            $address = $currentColumn . $currentRow;
            //读取到的数据，保存到数组$arr中
            $data[$currentRow][$currentColumn] = $currentSheet->getCell($address)->getValue();
        }
    }
    return $data;
}


echo "<pre>";
var_dump($data);
echo "</pre>";
//if ($data[])
foreach ($data as $v) {
    if ($v["A"] == "张三") {
        echo $v["B"];
//        header("location:i.php?dh={$v["B"]}&name={$v["A"]}");
        header("location:query.php?dh={$v["B"]}&name={$v["A"]}");
    }
}
